public class Table {
    static boolean check(char[][] field) {
        int fieldCol = field.length;
        int fieldRow = field[0].length;

        for (int c = 0; c < fieldCol; c++) {
            for (int r = 0; r < (fieldRow - 2); r++) {
                if (field[c][r] == field[c][r+1] && field[c][r] == field[c][r+2] && field[c][r] != ' ') {
                    return true;
                }
            }
        }

        for (int r = 0; r < fieldRow; r++) {
            for (int c = 0; c < (fieldCol - 2); c++) {
                if (field[c][r] == field[c+1][r] && field[c][r] == field[c+2][r] && field[c][r] != ' ') {
                    return true;
                }
            }
        }

        for (int c = 0; c < (fieldCol - 2); c++) {
            for (int r = 0; r < (fieldRow - 2); r++) {
                if (field[c][r] == field[c+1][r+1] && field[c][r] == field[c+2][r+2] && field[c][r] != ' ') {
                    return true;
                }
            }
        }

        for (int c = 0; c <= (fieldCol - 3); c++) {
            for (int r = (fieldRow - 1); r > 1; r--) {
                if (field[c][r] == field[c+1][r-1] && field[c][r] != ' ') {
                    if (field[c+2][r-2] == field[c][r]) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
}